/* SPDX-License-Identifier: GPL-2.0 */
#ifndef __MM_ETMEM_H_
#define __MM_ETMEM_H_

#include <asm/page.h>
#include <linux/list.h>
#include <linux/mmzone.h>
#include <linux/memcontrol.h>
#include <linux/page-flags.h>

#ifdef CONFIG_ETMEM
/**
 * list_for_each_entry_safe_reverse_from
 * @pos:	the type * to use as a loop cursor.
 * @n:		another type * to use as temporary storage
 * @head:	the head for your list.
 * @member:	the name of the list_head within the struct.
 *
 * Iterate backwards over list of given type from current point, safe against
 * removal of list entry.
 */
#define list_for_each_entry_safe_reverse_from(pos, n, head, member)		\
	for (n = list_prev_entry(pos, member);				\
		 &pos->member != (head);				\
		 pos = n, n = list_prev_entry(n, member))

int find_best_peer_node(int nid);
extern unsigned int sysctl_vmemmap_block_from_dram;

enum etmem_swapcache_watermark_en {
	ETMEM_SWAPCACHE_WMARK_LOW,
	ETMEM_SWAPCACHE_WMARK_HIGH,
	ETMEM_SWAPCACHE_NR_WMARK
};
extern struct kobj_attribute kernel_swap_enable_attr;

extern int add_page_for_swap(struct page *page, struct list_head *pagelist);
extern struct page *get_page_from_vaddr(struct mm_struct *mm,
					unsigned long vaddr);
extern int do_swapcache_reclaim(unsigned long *swapcache_watermark,
				unsigned int watermark_nr);
extern bool kernel_swap_enabled(void);
#else
static inline int add_page_for_swap(struct page *page, struct list_head *pagelist)
{
	return 0;
}

static inline struct page *get_page_from_vaddr(struct mm_struct *mm,
						unsigned long vaddr)
{
	return NULL;
}

static inline int do_swapcache_reclaim(unsigned long *swapcache_watermark,
					unsigned int watermark_nr)
{
	return 0;
}

static inline bool kernel_swap_enabled(void)
{
	return true;
}
#endif

#endif

